<?php

/**
 * EcsMsgtpl智能充电充值消息模板
 *
 * @author Administrator
 */
class EcsMsgtpl extends BaseMsgtpl
{
	/**
	 * 电费预警发消息给学生
	 * @param int $info  信息
	 * @param int $ele  剩余电量
	 * @param int $maxEle  预警电量
	 * @return bool
	 */
	public function warningSendMessage($ele,$maxEle,$userIdList,$ecsId,$address,$realName,$time)
	{
		if(count($userIdList) > 0){
			foreach($userIdList as $key=>$v){
				$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $v),'openid,subscribe');
				$url = C('site_url').'/base/ecs/index/ecs_id/'.$ecsId;
				//if ($wechatUserInfo['subscribe']) {
					if ($ecsId == 3) {  // 铁道后勤
						$this->wxTplSign = '9yd7FVvR6pfrzKjL-2cb4CR5x9zix8hsuek6X_NiHBM';
						$info = array(
							'first' => array("value" => '您好，截止'.date("Y-m-d H:i:s",$time).'，您的寝室电量剩余不足' . $maxEle . '度,请及时充值'),
							'keyword1' => array("value" => date('Y-m-d H:i:s')),
							'keyword2' => array("value" => $address[$key]),
							'keyword3' => array("value" => $ele.'度'),
							'remark' => array("value" => '请点此登录电费充值模块进行充值'),
						);
					}elseif($ecsId == 5){ // 农林
						$this->wxTplSign = 'e_Z4doEna81zm1j9hUe47c5ICm0bdmfY_k97rVumEgs';
						$info = array(
							'first' => array("value" => '您好，截止'.date("Y-m-d H:i:s",$time).'，您的寝室电量剩余不足' . $maxEle . '度,请及时充值'),
							'keynote1' => array("value" => $realName[$v]),
							'keynote2' => array("value" => $address[$key]),
							'keynote3' => array("value" => $ele.'度'),
							'remark' => array("value" => '请点此登录电费充值模块进行充值'),
						);
					}elseif($ecsId == 8){ // 杭师大
						$this->wxTplSign = 'w9ZfhuYNz8bCeFxQ2UZIienklsdFphh-_nMcUm1UlJE';
						$info = array(
							'first' => array("value" => '您好，截止'.date("Y-m-d H:i:s",$time).'，您的寝室电量剩余不足' . $maxEle . '度,请及时充值'),
							'keynote1' => array("value" => $realName[$v]),
							'keynote2' => array("value" => $address[$key]),
							'keynote3' => array("value" => $ele.'度'),
							'remark' => array("value" => '请点此登录电费充值模块进行充值'),
						);
					}elseif($ecsId == 9){//佐客
						$this->wxTplSign = 'x_nwfwbqQAQSB5BQOiIiOTtXdRyA-b_j3t5nKAS_gMA';
						$info = array(
							'first' => array("value" => '您好，截止'.date("Y-m-d H:i:s",$time).'，您的寝室电量剩余不足' . $maxEle . '度,请及时充值'),
							'keyword1' => array("value" => $address[$key].' '.$realName[$v]),
							'keyword2' => array("value" => $ele.'度'),
							'remark' => array("value" => '请点此登录电费充值模块进行充值'),
						);
					}
					$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $this->wxTplSign, $info, $url);
				//}
			}
		}
	}

	/**
	 * 长假监控消息模版
	 */
	public function monitorSendMessage($ecsId,$open_id,$room_name)
	{
			$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('openid' => $open_id),'openid,subscribe');
			$url = '';
			if ($ecsId == 8) {// 杭师大
				$this->wxTplSign = 'UC9nXWEsw2eFN0j6WEPgobN040deuYfpAlfMwcYhnjA';
				$info = array(
					'first' => array("value" => '管理员您好，您管理的寝室中有用电异常状况,请及时检查！'),
					'keyword1' => array("value" => $room_name),
					'keyword2' => array("value" => date('Y-m-d H:i:s')),
					'keyword3' => array("value" => '异常用电'),
					'remark' => array("value" => '用电系统自动告警'),
				);
			}elseif($ecsId == 5){ // 农林
				$this->wxTplSign = '69I3aRFB8hG3689vvb3wevEr2QGfn-83GXjI5olU6uc';
				$info = array(
					'first' => array("value" => '管理员您好，您管理的寝室中有用电异常状况,请及时检查！'),
					'keyword1' => array("value" => $room_name),
					'keyword2' => array("value" => date('Y-m-d H:i:s')),
					'keyword3' => array("value" => '异常用电'),
					'remark' => array("value" => '用电系统自动告警'),
				);
			}elseif($ecsId == 6){//滨江
				$this->wxTplSign = '4zAbFWV-gIYE7nZSTtDDME8I0vB7mlHA5qmkrqAyS3A';
				$info = array(
					'first' => array("value" => '管理员您好，您管理的寝室中有用电异常状况,请及时检查！'),
					'keyword1' => array("value" => $room_name),
					'keyword2' => array("value" => date('Y-m-d H:i:s')),
					'keyword3' => array("value" => '异常用电'),
					'remark' => array("value" => '用电系统自动告警'),
				);
			}
			$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $this->wxTplSign, $info, $url);

	}

	/**
	 * 电控通讯错误发送消息给管理员
	 * @param string $school  学校
	 * @param array $userId  用户wechat_id
	 * @param array $hubDeviceId  中控器设备id
	 * @return bool
	 */
	public function falseSendMessage($school,$userId,$hubDeviceId)
	{
		if($userId){
			foreach($userId as $key=>$v){
				$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('wechat_user_id' => $v),'openid,subscribe');
				if ($wechatUserInfo['subscribe']) {
					$this->wxTplSign = 'dwbHgazZMHrAel2q7SF-4sIjim-_kMfp-bB8S9qdXWI';
					$info = array(
						'first' => array("value" => $school.'智能用电系统中控器'.$hubDeviceId.'通讯异常，请及时处理'),
						'keyword1' => array("value" => '智能用电系统'),
						'keyword2' => array("value" => date('Y-m-d H:i:s')),
						'keyword3' => array("value" => '电表无指令返回'),
					);
				}
				$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $this->wxTplSign, $info);

			}
		}
	}
}
